package org.qiuqiu.interceptor;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.qiuqiu.pojo.User;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

/**
 * @author 杜秋野
 *
 */
public class CheckLogin extends AbstractInterceptor {

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		ActionContext ctx = invocation.getInvocationContext();
		HttpServletRequest request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);
		Map session = ctx.getSession();
		User user = (User) session.get("user");
		String userName = request.getParameter("user.userName");
		String password = request.getParameter("user.password");
		if(user!=null){
			return org.qiuqiu.action.UserAction.SUCCESS;
		}else if(userName!=null&&userName!=""&&password!=null&&password!=""){
			return invocation.invoke();
		}else{
			return org.qiuqiu.action.UserAction.INPUT;
		}
	}

}
